#
# Package.
#

package iSOCK::Controller::Admin::Users;

#
# Parent.
#

use Moose;
use namespace::autoclean;

BEGIN { extends 'iSOCK::Controller::Root' }

#
# Uses.
#

use File::Slurp qw( slurp );
use JSON;
use SOCK::BOT qw( x_to_y_hash_as_lol );
use SOCK::LOG;

#
# Documentation.
#

=head1 NAME

iSOCK::Controller::Users - Product Controller for iSOCK

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

#
# Subs.
#

sub index :Path :Args(0) {
  my ( $self, $c ) = @_;

  $self->check_user_authorization ( $c, 'can_bofh' );
  
  my $parameters = $c->request->parameters;
  
  if ( $c->request->method eq 'POST' && $parameters->{form_users_crud} ) {
    for my $id ( grep { defined } map { m/^delete_(\d+)$/ ? $1 : undef } keys %$parameters ) {
      $c->log->info ( "Deleting #$id user..." );
      
      if ( $c->model ( 'User' )->delete ({ c => $c, id => $id }) ) {
        $c->log->info ( "Done." );
      }
      else {
        $c->log->info ( "Failed." );
      }
    }
  }

  $c->stash ( user_rs => $c->model ( 'App::User' ) );

  $c->forward ( qw( iSOCK::Controller::Root render_view ) );
}

#
# Documentation.
#

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

#
# End of iSOCK::Controller::Users.
#

1;
